import { DateTime } from 'luxon'
import {column, BaseModel, hasMany, HasMany, beforeCreate} from '@ioc:Adonis/Lucid/Orm'
import uuid from 'uuid-v4'
import Skus from "App/Models/Skus";
export default class Spus extends BaseModel {
    @hasMany(() => Skus, {
       foreignKey: 'spuId',
    })
    public skus: HasMany<typeof Skus>
    public static selfAssignPrimaryKey = true
    public static table = 'tb_spus'
    @column({ isPrimary: true })
    public id: string
    @column()
    public name: string
    @column()
    public description: string
    @column.dateTime({ autoCreate: true })
    public createdAt: DateTime
    @column.dateTime({ autoCreate: true, autoUpdate: true })
    public updatedAt: DateTime
    @beforeCreate()
    public static assignUuid(spu: Spus) {
      spu.id = uuid()
    }
}
